package cn.edu.web;

import cn.edu.pojo.All;
import cn.edu.pojo.PageBean;
import cn.edu.pojo.teacher;
import cn.edu.service.impl.ExamineServiceImpl;
import cn.edu.service.ExamineService;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.List;

/**
 * @author Davey chan
 */
@WebServlet("/Examine/*")
public class ExamineServlet extends BaseServlet {
    private ExamineService tService = new ExamineServiceImpl();

//    同意审核
    public void agree(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回的教师ID
        String _id = request.getParameter("id");
        int id = Integer.parseInt(_id);

//        调用Service的同意
        tService.agree(id);
//        返回成功的标识
        response.getWriter().write("pass");
    }
//    不同意审核
public void disagree(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //接收页面返回的教师ID
    String _id = request.getParameter("id");
    int id = Integer.parseInt(_id);

//        调用Service的同意
    tService.disagree(id);
//        返回成功的标识
    response.getWriter().write("nopass");
}
//未审核分页查询
    public void selectByPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接受当前页码，和每页展示条数
        String _currentPage = request.getParameter("currentPage");
        String _pageSize = request.getParameter("pageSize");
        String _academyName = request.getParameter("academyName");
        byte[]  bytes = _academyName.getBytes("iso-8859-1");
        String  academyName = new String(bytes,"utf-8");

        int currentPage = Integer.parseInt(_currentPage);
        int pageSize= Integer.parseInt(_pageSize);
//
        PageBean<All> pageBean = tService.selectByPage(currentPage, pageSize,academyName);


//将集合转换成JSON数据，也叫序列化
        String jsonString = JSON.toJSONString(pageBean);
//        响应数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }

    //已审核分页查询
    public void selectByPage2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接受当前页码，和每页展示条数
        String _currentPage = request.getParameter("currentPage2");
        String _pageSize = request.getParameter("pageSize2");
        String _academyName = request.getParameter("academyName");
        byte[]  bytes = _academyName.getBytes("iso-8859-1");
        String  academyName = new String(bytes,"utf-8");
        int currentPage = Integer.parseInt(_currentPage);
        int pageSize= Integer.parseInt(_pageSize);
//
        PageBean<teacher> pageBean = tService.selectByPage2(currentPage, pageSize,academyName);


//将集合转换成JSON数据，也叫序列化
        String jsonString = JSON.toJSONString(pageBean);
//        响应数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }



    //    同意审核
    public void cancle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回的教师ID
        String _id = request.getParameter("id");
        int id = Integer.parseInt(_id);

//        调用Service的同意
        tService.cancle(id);
//        返回成功的标识
        response.getWriter().write("ok");


    }
}
